import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import { Row, Col, Card, DatePicker, Table, Tag } from 'antd'
import { color } from 'utils'
import List from './List'
import Details from './details'
import Modal from './modal'
import Info from './info'

const statistics = ({ location, dispatch, statistics, loading }) => {
	const { infoData, depUser, department2, details, showDetails, list, listDetais, visible, showInfo, department1, pagination2, params } = statistics
	//	console.log(department1)
	//	console.log(showInfo)
	const listProps = {
		list,
		listDetais,
		department1,
		onGroup(id) {
			dispatch({
				type: 'statistics/group',
				payload: { organizationId: id }
			})
		},
		onDetails(datas) {
			dispatch({
				type: 'statistics/details',
				payload: {
					...datas
				}
			})
		},
	}
	const detailsProps = {
		list,
		listDetais,
		pagination2,
		onPageChange(page) {
			const { query, pathname } = location
			dispatch({
				type: 'statistics/details',
				payload: {
					...query,
					organizationId: params.organizationId,
					departmentId: params.departmentId,
					state: params.state,
					page: page.current,
					pageSize: page.pageSize
				}
			})
		},
		onDeleteItem(item) {
			dispatch({
				type: 'statistics/delete',
				payload: item
			})
		},
		onComponent(item1, item2) {
			dispatch({
				type: 'statistics/complete',
				payload: {
					number: item1,
					state: item2,
				}
			})
		},
		onEidt(item, item1) {
			dispatch({
				type: 'statistics/info',
				payload: {
					number: item
				}
			}),
				dispatch({
					type: 'statistics/dep',
					payload: {
						parentId: item1
					}
				})
		},
		onInfo() {
			dispatch({
				type: 'statistics/showInfos',
				payload: {}
			})
		},
		onList() {
			dispatch({
				type: 'statistics/showLis',
				payload: {}
			})
		},
		showDetail(id) {
			dispatch({
				type: 'statistics/showInfos',
				payload: { number: id }
			})
		}
	}
	const modalProps = {
		visible,
		department2,
		infoData,
		depUser,
		onOk(params) {
			dispatch({
				type: 'statistics/update',
				payload: {
					...params
				}
			})
		},
		onCancels() {
			dispatch({
				type: 'statistics/onCancel',
				payload: {}
			})
		},
		onUsers(value) {
			dispatch({
				type: 'statistics/users',
				payload: { organizationId: value }
			})
		}
	}
	const infoProps = {
		details,
		showDetails() {
			dispatch({
				type: 'statistics/showDet',
				payload: {}
			})
		}
	}
	return (
		<div className="content-inner" style={{ backgroundColor: 'transparent', padding: 0 }}>
			<div style={{ display: showInfo ? "none" : "block" }}>
				<div style={{ display: showDetails ? "none" : "block" }}>
					<List {...listProps} />
				</div>
				<div style={{ display: showDetails ? "block" : "none" }}>
					<Details {...detailsProps} />
					<Modal {...modalProps} />
				</div>
			</div>
			<div style={{ display: showInfo ? "block" : "none" }}>
				<Info {...infoProps} />
			</div>
		</div>
	)

}
export default connect(({ statistics, loading }) => ({ statistics, loading }))(statistics)
